<template>
  <div>
    <el-select v-model="selectValue" placeholder="请选择" @change="select">
      <el-option
        v-for="item in selectData"
        :key="item.id"
        :label="item.label"
        :value="item.value"
      >
      </el-option>
    </el-select>
  </div>
</template>



<script>
import * as API from '@/api/admin/dict'
export default {
  data() {
    return {
      selectData: [],
      selectValue:''
    };
  },
  props: {
    value: {
      type: String|Number,
      default: "",
    },
    showAll:{
      type:Boolean,
      default:true
    },
    defaultValue:{
      type:Boolean,
      default:false
    }
  },
  watch: {
    value(val) {
      this.selectValue = val;
    },
  },
  methods: {
    query() {
      API.remote('equ_type').then((res) => {
        if (res.data.code === 0) {
          this.selectData = res.data.data;
          if(this.showAll){
            this.selectData.unshift({value:'-1',label:'全部设备'})
          }
          if(this.defaultValue){
            this.selectValue = this.selectData[0].value
          }
        }
      });
    },
    select(val) {
      this.$emit("input", val);
      let index = this.selectData.findIndex(item=>item.value==val)
      this.$emit('select',this.selectData[index])
    },
  },
  beforeMount(){
    this.query()
  }
};
</script>